import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'

import UserInfo from './views/UserInfo.vue'
import CookieInfo from './views/CookieInfo.vue'
import utils from './utils/utils'
import axios from './http'

Vue.use(Router)

const routes = [
  {
    name: 'home',
    path: '/home',
    component: Home
  },
// 当前选择城市页面
  {
    name: 'userinfo',
    path: '/userinfo',
    component: UserInfo
  },
  
  
  {
    name: 'userinfob',
    path: '/userinfob',
    meta: {
      requireAuth: true,  // 添加该字段，表示进入这个路由是需要登录的
    },
    component: () => import(/* webpackChunkName: 'city' */  `@/views/UserInfo.vue`)
  },
  
]
const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  
})
// 添加路由守卫
/*
next({
    path: '/login',
    query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由

  })
  isLogin ? next() : next("/login");
*/
router.beforeEach((to, from, next) => {
  const hasToken = localStorage.token ? true : false;
  if (to.path == "/userinfo" ) {
    //axios.get("http://localhost:8878/uouo").then(function(response) {

    //})
    if(hasToken){
      
    }
    next();
  } 
  
  next();
})
export default router